package com.onesports.intelligent.k12.polarlight.controller.operation.course;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.CourseDetailDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.CourseManagePageDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.CourseManegeSaveOrUpdateDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseDetailPageVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseDetailVo;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.CourseVO;
import com.onesports.intelligent.k12.polarlight.service.course.CourseManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author FPH
 * @since 2022年7月10日15:31:46
 */
@RestController
@Api(tags = "运营端-运营管理-课程管理")
@RequestMapping(ApiPathConstants.ORG_COURSE_MANAGE)
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class CourseClassManageController {

    private final CourseManageService courseManageService;

    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResponseEntity<IPage<CourseVO>> page(@RequestBody @Valid CourseManagePageDTO dto){
        return ResultUtil.success(courseManageService.queryCoursePage(dto));
    }

    @PostMapping("save-or-update")
    @ApiOperation(value = "保存修改通用接口")
    public ResponseEntity<String> updateOrSave(@RequestBody @Valid CourseManegeSaveOrUpdateDTO dto){
        return courseManageService.saveOrUpdate(dto)?ResultUtil.success("操作成功"):ResultUtil.success("操作失败");
    }

    @ApiOperation("通用删除")
    @PostMapping("delete")
    public ResponseEntity<String> delete(String id){
        return courseManageService.delete(id)?ResultUtil.success("删除成功"):ResultUtil.success("删除失败");
    }

    @ApiOperation("修改操作数据回显")
    @PostMapping("detail")
    public ResponseEntity<CourseDetailVo> queryDetailById(String id){
        return ResultUtil.success(courseManageService.queryDetailById(id));
    }


    @ApiOperation("查看详情")
    @PostMapping("detail-list")
    public ResponseEntity<CourseDetailPageVO> getDetail(@RequestBody @Valid CourseDetailDTO dto){
        return ResultUtil.success(courseManageService.getDetail(dto));
    }
}
